/**
 * 
 */
package swingPractice;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

/**
 * @author p@!
 *
 */
public class MenuActionListener implements ActionListener {

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		System.out.println("Item clicked: " + e.getActionCommand());
//		System.out.println(e.getSource());
		if (e.getActionCommand() == ("CREATE MAP")) // change it properly,,,
													// improper usage,,, change
													// the listener way to
													// e.source()
		{
			System.out.println("CREATE MAP");
			// JOptionPane.showMessageDialog(null, "asdf");
			// String row = JOptionPane.showInputDialog("DATA");
			
			JPanel rowColPanel = new JPanel();
			
			JTextField rowField = new JTextField(2);
			JTextField colField = new JTextField(2);
			
			NumberFormat f = NumberFormat.getNumberInstance(); 
			f.setMaximumIntegerDigits(2);
			JFormattedTextField numField = new JFormattedTextField(f);
			
			rowColPanel.setLayout(new BoxLayout(rowColPanel, BoxLayout.Y_AXIS));
			rowColPanel.add(new JLabel("Number of Rows :(Maximum : 50)", SwingConstants.CENTER));
			rowColPanel.add(rowField);
			
			rowColPanel.add(Box.createVerticalStrut(10)); // a spacer
			rowColPanel.add(new JLabel("Number of Columns :(Maximum : 50)"));
			rowColPanel.add(colField);
			rowColPanel.add(numField);
			int result = JOptionPane
					.showConfirmDialog(null, rowColPanel,
							"Please Enter Nuber of rows and columns",
							JOptionPane.OK_CANCEL_OPTION);
			if (result == JOptionPane.OK_OPTION) {
				System.out.println("row value: " + rowField.getText());
				System.out.println("col value: " + colField.getText());
				System.out.println("col value: " + numField.getText());
			}
		}
	}

}
